package com.lanhu.designpattern.singleton.threadlocal;

/**
 * author:zhangzg
 * date:2020/11/8 15:27
 */
public class Test {
    public static void main(String[] args) {
        //两个不同的线程内拿到的单例是一样，线程之间拿到的是不同的单例对象
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(SingletonTheadLocal.getInstance());
                System.out.println(SingletonTheadLocal.getInstance());
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(SingletonTheadLocal.getInstance());
                System.out.println(SingletonTheadLocal.getInstance());
            }
        });
        thread.start();
        thread2.start();
    }
}
